#include <QCoreApplication>
#include <QTENetwork/JICMPSocket>
#include <QHostAddress>
#include <QTimer>
#include <QDebug>

int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);
	QTE::JICMPSocket icmp(3000);

	auto pingLambda = [&icmp]()
	{
//        int id = icmp.ping(QHostAddress("114.114.114.114"));
//		int id = icmp.ping(QHostAddress("127.0.0.1"));
//		int id = icmp.ping("baidu.com");
//		int id = icmp.ping("dnf.qq.com");
//		int id = icmp.ping("gitee.com");
		int id = icmp.ping("bilibili.com");
		qDebug() << "id =" << id;
	};

	QObject::connect(&icmp, &QTE::JICMPSocket::pong,
					 [pingLambda](const QTE::JICMPSocket::PingResponse &response)
	{
		qDebug() << response.taskID << response.hostAddress
				 << response.averageTime << response.totalTime
				 << response.successCnt << "/" << response.totalCnt;

		QTimer::singleShot(1500, pingLambda);
	});

	pingLambda();
	return a.exec();
}
